package ru.netcracker.jcl.net;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.LinkedList;
import java.util.List;

import ru.netcracker.jcl.main.JavaCommandLine;

public class Server implements Runnable {

	private int port;
	List<Thread> threads = new LinkedList<Thread>();

	public Server(int port) {
		super();
		this.port = port;
	}

	@Override
	public void run() {
		try {
			ServerSocket serverSocket = new ServerSocket(port);
			while (true) {
				Socket socket = serverSocket.accept();
				Thread thread = new Thread(new JavaCommandLine(socket.getInputStream(), socket.getOutputStream()));
				threads.add(thread);
				thread.start();
				break;
			}
			serverSocket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
